﻿using System;
using System.Collections.Generic;
using UnityEditor.PackageManager;

public class ObjectPool<T> where T : new()
{
    private static Stack<T> m_Pool = new Stack<T>();
    public static T Claim()
    {
        if (m_Pool.Count == 0)
        {
            m_Pool.Push(new T());
        }
        return m_Pool.Pop();
    }
    public static void Release(T t)
    {
        m_Pool.Push(t);
    }
}

public class ListPool<T>
{
    private static readonly List<List<T>> m_pool = new List<List<T>>();
    public static List<T> Claim()
    {
        if (m_pool.Count == 0)
        {
            return new List<T>(128);
        }
        int idx = m_pool.Count - 1;
        var list = m_pool[idx];
        m_pool.RemoveAt(idx);
        return list;
    }
    public static void Release(List<T> list)
    {
        if (list == null) return;
        list.Clear();
        m_pool.Add(list);
    }
}